<?php

class Player
{
    private $_piece = null;
    private $_space = null;
    private $_turns_played = 0;

    public function __construct($piece, $space)
    {
        $this->setPiece($piece);
        $this->setSpace($space);
    }

    public function setPiece($piece)
    {
        $this->_piece = $piece;
    }

    public function getPiece()
    {
        return $this->_piece;
    }

    public function setSpace($space)
    {
        $this->_space = $space;
    }

    public function getSpace()
    {
        return $this->_space;
    }

    public function setTurnsPlayed($turns_played)
    {
        $this->_turns_played = $turns_played;
    }

    public function getTurnsPlayed()
    {
        return $this->_turns_played;
    }

    public function incrementTurnsPlayed()
    {
        $turns_played = $this->getTurnsPlayed();
        $this->setTurnsPlayed($turns_played + 1);
    }

    public function takeTurn($dice)
    {
        // get necessary info
        $space = $this->getSpace();
        $piece = $this->getPiece();
        $num_spaces = $dice->roll();

        // do the turn
        $new_space = $piece->move($num_spaces, $space);
        $this->setSpace($new_space);

        // update turns played
        $this->incrementTurnsPlayed();
    }

    public function __toString()
    {
        return $this->getPiece()->getName();
    }
}
